﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using KPIS.GERP.GIMS.MODEL;
using KPIS.GERP.GIMS.IBLL;
using KPIS.GERP.GIMS.IDAL;
using KPIS.GERP.GIMS.DALFactory;
using KPIS.GERP.GIMS.DAL;
using KPIS.DBM;

namespace KPIS.GERP.GIMS.BLL
{
    public class RecevieItemBLL
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        private static readonly ReceiveItemDAL dal = new ReceiveItemDAL();

        public RecevieItemBLL()
        {

        }
        public IList<ReceiveItemInfo> GetReceiveItems(Nullable<int> Sequence, Nullable<int> ReceiveSeq, string SearchText)
        {
            return dal.GetReceiveItems(Sequence, ReceiveSeq, SearchText);
        }
        public string InsertReturnSerialNo(ReceiveItemInfo info)
        {
            return dal.InsertReturnSerialNo(info);
        }
        public void Insert(ReceiveItemInfo info)
        {
            dal.Insert(info);
        }
        public void Update(ReceiveItemInfo info)
        {
            dal.Update(info);
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            dal.Delete(Sequence, UpdatedBy);
        }
        public void DeleteAll(IList<ReceiveItemInfo> infoList)
        {
            dal.DeleteAll(infoList);
        }
        //public void Insert(MasterUnitInfo info)
        //{
        //    string strSQL;
        //    try
        //    {
        //        dbManager.Open();
        //        dbManager.CreateParameters(6);

        //        dbManager.AddParameters(0, "@code", info.Code);
        //        dbManager.AddParameters(1, "@name", info.Name);
        //        dbManager.AddParameters(2, "@descr", info.Descr);
        //        dbManager.AddParameters(3, "@record_status", SystemInfo._WorkRecordStatus);
        //        dbManager.AddParameters(4, "@created_by", info.InfoRecord.Created_by);
        //        dbManager.AddParameters(5, "@created_when", info.InfoRecord.Created_when);

        //        strSQL = "INSERT INTO ICM_MAS_UNIT"
        //            + " (ICM_UNIT_CODE, ICM_UNIT_NAME, ICM_UNIT_DESCR"
        //            + " , RECORD_STATUS, CREATED_BY, CREATED_WHEN)"
        //            + " VALUES(@code"
        //            + ", @name"
        //            + ", @descr"
        //            + ", @record_status"
        //            + ", @created_by"
        //            + ", @created_when"
        //            + " )";

        //        dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
        //    }
        //    catch
        //    {
        //        throw;
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }
        //}


        public DataTable Select()
        {

            try
            {
                DataSet ds = new DataSet();
                DataTable dt;
                string sql;

                sql = "select * from icm_receive";
                dbManager.Open();
                ds = dbManager.ExecuteDataSet(CommandType.Text, sql);
                dt = ds.Tables[0].Copy();

                return dt;
            }

            catch (Exception ex)
            {
                throw (ex);
                //return null;
            }
            finally
            {
                dbManager.Dispose();
            }



        }
        ///<summary>
        /// โหลดประเภทการเคลื่อนไหว รับโอน  บริจาค  ยอดยกมา....... 
        /// </summary>
        public DataTable SelectMMTypeInv()
        {

            try
            {
                DataSet ds = new DataSet();
                DataTable dt;
                string sql;

                sql = "select icm_mm_type_seq as seq,icm_mm_type_name as name from icm_movement_type";
                dbManager.Open();
                ds = dbManager.ExecuteDataSet(CommandType.Text, sql);
                dt = ds.Tables[0].Copy();

                return dt;
            }

            catch (Exception ex)
            {
                throw (ex);
                //return null;
            }
            finally
            {
                dbManager.Dispose();
            }

        }
    }
}

